﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace Light.Utility
{
    public class CPU
    {
        
        private long _cache = -9223372036854775808L;
        private string _caption = null;
        private string _id = null;
        private string _manufacturer = null;
        private long _speed = -9223372036854775808L;

        
        private CPU()
        {
        }

        internal static CPU[] Get()
        {
            List<CPU> list = new List<CPU>();
            ManagementObjectCollection instances = new ManagementClass("Win32_Processor").GetInstances();
            foreach (ManagementObject obj2 in instances)
            {
                CPU item = new CPU();
                if (obj2.Properties["ProcessorId"].Value != null)
                {
                    item._id = obj2.Properties["ProcessorId"].Value.ToString();
                }
                else
                {
                    item._id = string.Empty;
                }
                if (obj2.Properties["Manufacturer"].Value != null)
                {
                    item._manufacturer = obj2.Properties["Manufacturer"].Value.ToString();
                }
                else
                {
                    item._manufacturer = string.Empty;
                }
                if (obj2.Properties["Caption"].Value != null)
                {
                    item._caption = obj2.Properties["Caption"].Value.ToString();
                }
                else
                {
                    item._caption = string.Empty;
                }
                if (obj2.Properties["MaxClockSpeed"].Value != null)
                {
                    item._speed = long.Parse(obj2.Properties["MaxClockSpeed"].Value.ToString());
                }
                if (obj2.Properties["L2CacheSize"].Value != null)
                {
                    item._cache = long.Parse(obj2.Properties["L2CacheSize"].Value.ToString());
                }
                list.Add(item);
            }
            return list.ToArray();
        }

        
        public string Caption
        {
            get
            {
                return this._caption;
            }
        }

        public long L2CacheSize
        {
            get
            {
                return this._cache;
            }
        }

        public string Manufacturer
        {
            get
            {
                return this._manufacturer;
            }
        }

        public long MaxClockSpeed
        {
            get
            {
                return this._speed;
            }
        }

        public string ProcessorId
        {
            get
            {
                return this._id;
            }
        }
    }



}
